package com.example.fw;


public class ContactHelper extends HelpersBase{

	public ContactHelper(AppManager appManager) {
		super(appManager);
	}

	public void createContact (Contact contact) {
		initContactCreation();
		fillContactForm(contact);
		confirmContactCreation();
		
	}
	
	public void fillContactForm(Contact contact) {
		manager.getAutoItHelper()
			.send("TDBEdit12", contact.firstname)
			.send("TDBEdit11", contact.lastname);
	}

	public void initContactCreation() {
		manager.getAutoItHelper()
			.winWaitAndActivate("AddressBook Portable", "", 5000)
			.click("Add")
			.winWaitAndActivate("Add Contact", "",   5000);
	}

	public void confirmContactCreation() {
		manager.getAutoItHelper()
			.click("Save")
			.winWaitAndActivate("AddressBook Portable", "", 5000);
	}

	public Contact getFirstContact() {
		manager.getAutoItHelper()
			.winWaitAndActivate("AddressBook Portable", "", 5000)
			.click("TListView1")
			.send("{DOWN}{SPACE}")
			.click("Edit")
			.winWaitAndActivate("Update Contact", "", 5000);
		
		Contact contact = new Contact()
				.setFirstName(manager.getAutoItHelper().getText("TDBEdit12"))
				.setLastName(manager.getAutoItHelper().getText("TDBEdit12"));
		
		manager.getAutoItHelper()
			.click("Cancel")
			.winWaitAndActivate("AddressBook Portable", "", 5000);
		
		return contact;
	}

	public void removeContact() {
		manager.getAutoItHelper()
			.winWaitAndActivate("AddressBook Portable", "", 5000)
			.click("TListView1")
			.send("{DOWN}{SPACE}")
			.click("Delete")
			.winWaitAndActivate("Confirm", "", 5000)
			.click("&Yes")
			.winWaitAndActivate("AddressBook Portable", "", 5000);
	}

	public void removeAllContacts() {
		manager.getAutoItHelper()
			.winWaitAndActivate("AddressBook Portable", "", 5000)
			.click("TListView1")
			.click("Select All")
			.click("Delete")
			.winWaitAndActivate("Confirm", "", 5000)
			.click("&Yes")
			.winWaitAndActivate("AddressBook Portable", "", 5000);
	}
	
	public void checkContactExists() {
		manager.getAutoItHelper()
			.winWaitAndActivate("AddressBook Portable", "", 5000)
			.click("TListView1")
			.send("{DOWN}{SPACE}")
			.click("Edit")
			.winWaitAndActivate("Information", "", 5000)
			.click("OK")
			.winWaitAndActivate("AddressBook Portable", "", 5000);
	}
}
